# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
"""Learning rate schedule for parser training."""

from mxnet.lr_scheduler import LRScheduler


class ExponentialScheduler(LRScheduler):
    """A simple learning rate decay scheduler
        lr = base_lr * decay_rate ^ (num_update / decay_every)

    Parameters
    ----------
    base_lr : float
        the initial learning rate.
    decay_rate : float
        what percentage does the learning rate decreases to in every decay compared to last one
    decay_every : float
        how often does the decay occurs
    """
    def __init__(self, base_lr=0.01, decay_rate=0.5, decay_every=1):
        super().__init__(base_lr)
        self.decay_rate = decay_rate
        self.decay_every = decay_every

    def __call__(self, num_update):
        return self.base_lr * self.decay_rate ** (num_update / self.decay_every)
